export default {
	data (){
		return {
			// value4: '',//搜索框
            loading: false,//表单懒加载
        	formValidate: {//表单
                title: '',
                author: '',
                otherTitle: '',
                date: '',
                style:[],
                tips:[],
                imgUrl:'',
                id: '',//表单的隐藏域用于储存id
            },
            data6: [//动态获取请求到的数据
            ],
            pageData: {
                total:20,
                limit: 10,
                page: 1,
                pages: 2,
                title:''//文章的名字，按条件搜索
            },
            select: []

		}
	},
	methods: {
		reload () {//得到数据对页面的重新载入
	       this.$http({
                method:"POST",
                url:`http://localhost:3000/${ this.module }/list`,
                data:this.pageData
            })
	        .then((response) => {
	            this.data6 = response.data.rows;
	            this.pageData.total = response.data.total;
	        })
	        .catch((response) => {});
	    },
		formDataCreate (){//表单提交新数据
            var data = this.formValidate;
            // delete data.id;
           this.$http({
                method:"POST",
                url:`http://localhost:3000/${ this.module }/data`,
                data:this.formValidate
            })
            .then((response) => {
                this.reload();
            })
            .catch((response) => {
                console.log(response)
            });
        },
        formDataUpdate (that_id){//表单修改
            this.$http({
                method:"POST",
                url:`http://localhost:3000/${ this.module }/data`+that_id,
                data:this.formValidate
            })
            .then((response) => {
                this.reload();
            })
            .catch((response) => {
                console.log(response)
            });
        },
        remove (index,id) {//删除与批量删除
            // if (this.select == 0 ) {
                
                if (this.select.length) {
                    this.$Message.warning('请选择批量删除');
                    return;
                }else{
                    this.data6.splice(index, 1);
                    this.$http({
                        method:"DELETE",
                        url:`http://localhost:3000/${ this.module }/data`+id,
                            // data:this.formValidate
                    })
                    .then((response) => {
                        console.log('成功')
                        this.reload();

                    })
                    .catch((response) => {
                        console.log("失败"+response)
                    });
                }
            },
            allremove(index,id) {//批量删除
                if(!this.select.length) {
                    this.$Message.warning('请选择删除的条目');
                    return;
                }else{
                    this.isRemoveModal = true;
                }
            },
            okremove() {
                this.okremove_loading = true;//loding加载环
                setTimeout(() => {
                    this.okremove_loading = true;
                    var idBox = [];
                    for (var i = 0; i < this.select.length; i++) {
                        idBox.push(this.select[i]._id);
                    }
                    console.log(idBox);
                    this.$http({
                        method:"DELETE",
                        url:'http://localhost:3000/users/data'+idBox,
                            // data:this.formValidate
                    })
                    .then((response) => {
                        this.isRemoveModal = false; 
                        this.$Message.success('删除成功');           
                        this.okremove_loading = false;
                        this.select = [];//删除成功后将checkbox中的
                        this.reload();
                    })
                    .catch((response) => {
                        this.isRemoveModal = false; 
                        this.$Message.warning('服务器异常');
                        this.okremove_loading = false;
                        console.log(response)
                    });
                },2000)
            },
            // }
            // else {
            //     this.warning();
            //     var idBox = [];
            //     for (var i = 0; i < this.select.length; i++) {
            //         idBox.push(this.select[i]._id);
            //     }
            //     console.log(idBox);
            //     this.$http({
            //         method:"DELETE",
            //         url:'http://localhost:3000/users/data'+idBox,
            //             // data:this.formValidate
            //     })
            //     .then((response) => {
            //         this.reload();
            //     })
            //     .catch((response) => {
            //         console.log(response)
            //     });
            // }
        search () {//搜索
       		this.reload();
        },
        changePage(page){//分页方法
            this.loading = true;
            var that = this;
            var tableTimer = setTimeout(function() {
                that.loading = false;
            }, 600);

            this.$http({
                method:'POST',
                url:`http://localhost:3000/${ this.module }/list`,
                data:{
                    page:page,
                }
            }).then((response)=>{
                this.data6 = response.data.rows;
            })
        },
        changePageSize(limit) {//一页最大数据数码
            this.loading = true;
            var that = this;
            var tableTimer = setTimeout(function() {
                that.loading = false
            }, 600);
            this.$http({
                method:'POST',
                url:`http://localhost:3000/${ this.module }/list`,
                data:{
                    rows:limit
                }
            }).then((response)=>{
                this.data6 = response.data.rows;
            })
        },
	},
	created: function() {//钩子函数创建
        this.reload();
    },

}